package com.foreverwin.jzymes.common.service.impl;

import com.foreverwin.jzymes.common.mapper.ResourceTypeAdviceMapper;
import com.foreverwin.jzymes.common.service.IResourceTypeAdviceService;
import com.foreverwin.jzymes.common.service.ISiteAdviceService;
import com.foreverwin.jzymes.common.util.BOHandleUtil;
import com.foreverwin.jzymes.framework.util.I18nUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;
import java.util.Map;

@Service
public class ResourceTypeAdviceServiceImpl implements IResourceTypeAdviceService {

    @Autowired
    ISiteAdviceService siteAdviceService;
    @Autowired
    ResourceTypeAdviceMapper resourceTypeAdviceMapper;

    /**
     * 查询资源类型资源
     *
     * @param site
     * @param resourceType
     * @return
     */
    public List<Map<String,String>> findResourceList( String site, String resourceType ){
        Assert.hasText( site, I18nUtil.getI18nText( "common.siteNotBlank" ));
        Assert.hasText( resourceType, I18nUtil.getI18nText( "common.resourceTypeNotBlank" ));
        String resourceTypeBo = BOHandleUtil.buildResourceTypeHandle( site, resourceType );
        return findResourceList( resourceTypeBo );
    }

    /**
     * 查询资源类型资源
     *
     * @param resourceTypeBo
     * @return
     */
    public List<Map<String,String>> findResourceList( String resourceTypeBo ){
        Assert.hasText( resourceTypeBo, I18nUtil.getI18nText( "common.resourceTypeNotBlank" ));

        return resourceTypeAdviceMapper.selectResourceList( resourceTypeBo );
    }

    /**
     * 查询资源类型资源
     *
     * @param site
     * @param resource
     * @param resourceType
     * @return
     */
    public Map<String,Object> findResourceByResourceType( String site, String resource, String resourceType ){
        /**检查站点*/
        siteAdviceService.existSite( site );
        /**检查设备编号*/
        Assert.hasText( resource, I18nUtil.getI18nText("common.resourceNotBlank") );
        /**检查设备类型*/
        Assert.hasText( resourceType, I18nUtil.getI18nText("common.resourceTypeNotBlank") );

        String resourceBo = BOHandleUtil.buildResourceHandle( site, resource );
        String resourceTypeBo = BOHandleUtil.buildResourceTypeHandle( site, resourceType );
        return resourceTypeAdviceMapper.selectResourceByResourceType( resourceTypeBo, resourceBo );
    }

    /**
     * 查询资源类型对应的工序
     *
     * @param site
     * @param resourceType
     * @return
     */
    /*public Map<String,Object> findOperationMap( String site, String resourceType ){
        Assert.hasText( site, I18nUtil.getI18nText( "common.siteNotBlank" ));
        Assert.hasText( resourceType, I18nUtil.getI18nText( "common.resourceTypeNotBlank" ));
        String resourceTypeBo = BOHandleUtil.buildResourceTypeHandle( site, resourceType );
        Map<String,Object> operationMap = resourceTypeAdviceMapper.selectOperation( resourceTypeBo );

        Assert.notNull( operationMap, I18nUtil.getI18nText( "common.operationOnResourceTypeNotExist", new String[]{ resourceType } ) );
        return operationMap;
    }*/

    /**
     * 查询资源类型对应的工序
     *
     * @param site
     * @param resourceType
     * @return
     */
    /*public String findOperation( String site, String resourceType ){
        Map<String,Object> operationMap = findOperationMap( site, resourceType );

        return (String) operationMap.get( "OPERATION" );
    }*/

    /**
     * 查询资源类型对应的工序
     *
     * @param site
     * @param resourceType
     * @return
     */
    /*public String findOperationBo( String site, String resourceType ){
        Map<String,Object> operationMap = findOperationMap( site, resourceType );

        return (String) operationMap.get( "HANDLE" );
    }*/
}
